docs: link manpage cross-references in HTML output - #4246
Conversation
Add an asciidoctor postprocessor that turns name(section) references in the HTML manpages into clickable links to the sibling page. Index-gated against the rendered troff tree so false positives (enum values, external and misspelled pages) stay plain text; self-links, code spans and existing links are left untouched. Wired into the manpage HTML rule via manxref-root.
motion(1) and hal_thread_new(3) name pages that do not exist. Point them at the actual pages motion(9) and hal_create_thread(3).
Extend the man_xref postprocessor to the User/HAL/Integrator HTML manuals, which cite man pages in the same name(section) form. A per-page manxref-linkbase attribute carries the depth-adjusted path to the language's man/man<N>/ tree; manpages keep the sibling default. Index-gated as before, so only real pages link and prose like TRUE(1) stays plain.
1be89ba to
653e6cf
Compare
|
Some parts of the manual pages are a bit stale and needs cleaning up. In fact, I was doing exactly that for the hal_*(3) set of pages and adding a lot of them when this issue of linking caught my attention. |
|
Should I drop the doc fixes then? just have the script? |
No, your fixes are just fine. The "other" fixes is to read them all from start to end, fix inconsistencies, add missing, remove obsolete and reformat them to become uniform. But that is a different affair of incremental changes over a longer period. |
|
One thing though, maybe add to lcnc-overrides.css: .man-xref {
font-family: monospace;
font-size: 90%;
}We'll tackle the spurious bolds, italics and splits ( |
| html.scan(/([^<]+)|(<[^>]*>)/) do | ||
| text, tag = Regexp.last_match(1), Regexp.last_match(2) |
There was a problem hiding this comment.
Isn't there supposed to be at least one char in between the '<' and '>' in a tag? How are you catching <mytag attrib="<oops>">?
The "proper" way to look at HTML is to use a HTML/XML parser and then find the text nodes matching the manpage(sec) pattern. That would be safer than regex parsing, which is known to be unstable for structured files like HTML.
Wouldn't it just be better to do this in a Tree-processor extension?
There are examples of tree-processors: https://github.com/asciidoctor/asciidoctor-extensions-lab/tree/main/lib/
You should also be able to check for the selected output format while it is running.
Addresses #4244.
What
Adds an asciidoctor postprocessor (
docs/src/extensions/man_xref.rb) that turnsname(section)manpage references (halcmd(1),stepgen(9), ...) into clickable links to the corresponding HTML page. Applied to both:man/), and../man/manN/.Wired into both HTML rules in
docs/src/Submakefile. Per-pagemanxref-root(troff tree) andmanxref-linkbase(depth-adjusted path) attributes drive it; absent => no-op.How it stays correct
Index-gated: a token links only when a real page
name.sectionexists in that language's troff tree. Common false positives resolve to nothing and stay plain, with no skip list:feed(2)/arc(3)inmotion(9)open(2),printf(3),udev(8)TRUE(1),time.sleep(1)Also: never self-links; skips
<a> <code> <pre> <script> <style> <head> <title> <h1>(code, attributes, existing links untouched); case-insensitive match with verbatim visible text.Verification
de/man/).BUILD_DOCS_TRANSLATED=yesbuild currently cannot complete due to a pre-existing po4a NAME-drift issue (a stray space in a German man page NAME yields a dangling.soalias), tracked in docs: pin manpage troff filename to the make target #4193 / CI: Check html links for doc #4178. Unrelated to this change; the links themselves render correctly per language.Also included
Source refs the linker surfaced as broken, fixed to the real pages:
motion(1)=>motion(9)inhal_manualtoolchange(1)hal_thread_new(3)=>hal_create_thread(3)inhal_add_funct_to_thread(3)stegen(9)=>stepgen(9)in the hostmot2 driver docsNotes
link:refs (e.g.SSERIAL(9),debounce(9)) are left untouched: the postprocessor skips anything already inside an<a>.hm2_uart_setup_chan(3)inhostmot2(9)names no existing page; left as-is. @pcw-mesa stale/renamed name, or a missing page?